package com.cn.yang.service.impl;

import com.cn.yang.dao.UserDao;
import com.cn.yang.dao.impl.UserDaoImpl;
import com.cn.yang.model.UserModel;
import com.cn.yang.service.UserService;
import com.cn.yang.util.PageUtil;

import java.sql.ResultSet;
import java.util.List;


public class UserServiceImpl implements UserService {
    UserDao userDao = new UserDaoImpl();
    @Override
    public int registerUser(UserModel userModel) {
        int result = userDao.registerUser(userModel);
        //插入成功返回1
        if (result==1){
            return 1;
        }else if (result==-1){
            return -1;
        }
        return result;
    }

    @Override
    public int login(UserModel userModel) {
        //-1 账号不存在 1 登录成功 2 密码不正确////验证码错误 返回3
        if (userModel.getCode().equals(userModel.getSessionCode())){
            int result = userDao.login(userModel);
            return result;
        }else {
            return 3;
        }

    }

    @Override
    public List<UserModel> findAllUser(UserModel userModel) {
        UserDao userDao = new UserDaoImpl();
        List<UserModel> list = userDao.findAllUser(userModel);
        return list;
    }

    @Override
    public int deleteById(Integer id) {
        UserDao userDao = new UserDaoImpl();
        //i删除成功 返回 1 ，删除失败返回 0
        return userDao.deleteById(id);
    }

    @Override
    public UserModel selectById(Integer id) {
        UserDao userDao = new UserDaoImpl();
        return userDao.findIdUser(id);
    }

    @Override
    public int updateById(UserModel userModel) {
        UserDao userDao = new UserDaoImpl();
        return userDao.updateUser(userModel);
    }

    @Override
    public List<UserModel> findSomeUser(UserModel userModel) {
        UserDao userDao = new UserDaoImpl();
        return userDao.findSomeUser(userModel);
    }

    @Override
    public int countUser() {
        UserDao userDao = new UserDaoImpl();
        return userDao.countUser();
    }
}
